package com.java.admin.news.controller;

import com.java.admin.news.service.NewsService;
import com.java.database.entity.News;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class NewsController {

    @Autowired
    private NewsService newsService;

    @ResponseBody
    @RequestMapping("/queryNews")
    public List<News> query() {

        return newsService.query();
    }

    @RequestMapping("/insertNews")
    public String insert(News news) {

        newsService.insertNews(news);
        return "redirect:/admin/news.html";
    }

    @RequestMapping("/deleteNews")
    public String delete(HttpRequest request,News news) {

        newsService.deleteNews(news);
        return "redirect:/admin/news.html";
    }

    @RequestMapping("/updateNews")
    public String update(HttpRequest request, News news) {
        newsService.updateNews(news);
        return "redirect:/admin/news.html";
    }
}


